<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>

    </head>

    <script src="https://sellpow-html.oss-cn-beijing.aliyuncs.com/public/js/aes.js"></script>
    <body>
    <script>
        var key = CryptoJS.enc.Utf8.parse("8NONwyJtHesysWpM");
        var plaintText = 'ABCDEFGH'; // 明文
        var encryptedData = CryptoJS.AES.encrypt(plaintText, key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        console.log("加密前："+plaintText);
        console.log("加密后："+encryptedData);
        encryptedData = encryptedData.ciphertext.toString();
        var encryptedHexStr = CryptoJS.enc.Hex.parse(encryptedData);
        var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);
        var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });

        var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);

        console.log("解密后:"+decryptedStr);


        var pwd = "PCsUFtgog9/qpqmqXsuCRQ==";
        //加密服务端返回的数据
        var decryptedData = CryptoJS.AES.decrypt(pwd, key, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });

        console.log("解密服务端返回的数据:"+decryptedStr);

    </script>
    <script>  //aes封装的加密解密函数
        function getAesString(data,key,iv){//加密
            var key  = CryptoJS.enc.Utf8.parse(key);
            var iv   = CryptoJS.enc.Utf8.parse(iv);
            var encrypted =CryptoJS.AES.encrypt(data,key,
                {
                    iv:iv,
                    mode:CryptoJS.mode.CBC,
                    padding:CryptoJS.pad.Pkcs7
                });
            return encrypted.toString();    //返回的是base64格式的密文
        }
        function getDAesString(encrypted,key,iv){//解密
            var key  = CryptoJS.enc.Utf8.parse(key);
            var iv   = CryptoJS.enc.Utf8.parse(iv);
            var decrypted =CryptoJS.AES.decrypt(encrypted,key,
                {
                    iv:iv,
                    mode:CryptoJS.mode.CBC,
                    padding:CryptoJS.pad.Pkcs7
                });
            return decrypted.toString(CryptoJS.enc.Utf8);
        }

        function getAES(data){ //加密
            var key  = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';  //密钥
            var iv   = '1234567812345678';
            var encrypted =getAesString(data,key,iv); //密文
            var encrypted1 =CryptoJS.enc.Utf8.parse(encrypted);
            return encrypted;
        }

        function getDAes(data){//解密
            var key  = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';  //密钥
            var iv   = '1234567812345678';
            var decryptedStr =getDAesString(data,key,iv);
            return decryptedStr;
        }
    </script>
    </body>
    </html>